package com.ch.viewmodeldemo

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.Button
import android.widget.TextView
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelProviders

class MainActivity : AppCompatActivity() {
    private lateinit var mNumberTv: TextView
    private lateinit var mCountBt: Button
    private lateinit var viewModel:MyViewModel
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        mNumberTv = findViewById(R.id.numberTV)
        mCountBt = findViewById(R.id.countBt)
        viewModel= ViewModelProviders.of(this).get(MyViewModel::class.java)
        mNumberTv.text = "${viewModel.curNumber}"
    }

    fun addNumber(view: android.view.View) {
        Log.e("Hogan","${++viewModel.curNumber}")
        mNumberTv.text = "${viewModel.curNumber}"

    }
}